package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.mapper.CartMapper;
import com.situ.mall.pojo.entity.Cart;
import com.situ.mall.pojo.vo.CartListVO;
import com.situ.mall.service.ICartService;

@Service
public class CartServiceImpl implements ICartService{
	@Autowired
	private CartMapper cartMapper;
	
	@Override
	public boolean insertCart(Cart cart) {
		int count = cartMapper.isHave(cart);
		if (count == 1) {
			count = cartMapper.addQuantity(cart);
		} else {
			count = cartMapper.insert(cart);
		}
		return count == 1;
	}

	@Override
	public List<CartListVO> selectByUser(Integer id) {
		List<CartListVO> list = cartMapper.selectByUser(id);
		return list;
	}

	@Override
	public boolean updateQuantity(Integer productId, Integer quantity, Integer id) {
		int count = cartMapper.updateQuantity(productId, quantity, id);
		return count == 1;
	}

	@Override
	public boolean deleteById(Integer cartId) {
		int count = cartMapper.deleteByPrimaryKey(cartId);
		return count == 1;
	}

	@Override
	public boolean updateStatus(Integer cartId, Integer checked) {
		int count = cartMapper.updateStatus(cartId, checked);
		return count == 1;
	}

	@Override
	public boolean updateStatusAll(Integer userId, Integer checkedall) {
		int count = cartMapper.updateStatusAll(userId, checkedall);
		return count == 1;
	}

	@Override
	public List<CartListVO> selectCheckByUser(Integer id) {
		List<CartListVO> list = cartMapper.selectCheckByUser(id);
		return list;
	}

}
